class Page1 extends egret.DisplayObjectContainer {
	private bmp_bg: egret.Bitmap;
	private bmp_t0: egret.Bitmap;
	private bmp_t1: egret.Bitmap;
	private bmp_t2: egret.Bitmap;
	private bmp_t3: egret.Bitmap;
	private bmp_2017: egret.Bitmap;
	private bmp_tip1: egret.Bitmap;
	private bmp_tip2: egret.Bitmap;
	private mc: egret.MovieClip;
	private particle: particle.GravityParticleSystem;
	public constructor() {
		super();

		this.bmp_bg = new egret.Bitmap();
		this.bmp_bg.texture = RES.getRes('p1_bg_png');
		// this.bmp_bg.anchorOffsetX=this.bmp_bg.width/2;
		// this.bmp_bg.anchorOffsetY=this.bmp_bg.height/2;
		this.bmp_bg.x = 0;
		this.bmp_bg.y = 0;
		this.addChild(this.bmp_bg);

		this.bmp_t0 = new egret.Bitmap();
		this.bmp_t0.texture = RES.getRes('p1_t0_png');
		this.bmp_t0.anchorOffsetX = this.bmp_t0.width / 2;
		this.bmp_t0.anchorOffsetY = this.bmp_t0.height / 2;
		this.bmp_t0.x = 378;
		this.bmp_t0.y = 79;
		this.bmp_t0.alpha = 0;
		this.addChild(this.bmp_t0);

		this.bmp_t1 = new egret.Bitmap();
		this.bmp_t1.texture = RES.getRes('p1_t1_png');
		this.bmp_t1.anchorOffsetX = this.bmp_t1.width / 2;
		this.bmp_t1.anchorOffsetY = this.bmp_t1.height / 2;
		this.bmp_t1.x = 370;
		this.bmp_t1.y = 210;
		this.bmp_t1.scaleX=this.bmp_t1.scaleY=0.9;
		this.bmp_t1.alpha = 0;
		this.addChild(this.bmp_t1);

		this.bmp_t2 = new egret.Bitmap();
		this.bmp_t2.texture = RES.getRes('p1_t2_png');
		this.bmp_t2.anchorOffsetX = this.bmp_t2.width / 2;
		this.bmp_t2.anchorOffsetY = this.bmp_t2.height / 2;
		this.bmp_t2.x = 374;
		this.bmp_t2.y = 357;
		this.bmp_t2.alpha = 0;
		this.bmp_t2.scaleY=this.bmp_t2.scaleX=1.1;
		this.addChild(this.bmp_t2);

		this.bmp_t3 = new egret.Bitmap();
		this.bmp_t3.texture = RES.getRes('p1_t3_png');
		this.bmp_t3.anchorOffsetX = this.bmp_t3.width / 2;
		this.bmp_t3.anchorOffsetY = this.bmp_t3.height / 2;
		this.bmp_t3.x = 374;
		this.bmp_t3.y = 437;
		this.bmp_t3.alpha = 0;
		this.addChild(this.bmp_t3);

		this.particle = new particle.GravityParticleSystem(RES.getRes("leaf_png"), RES.getRes("leaf_json"));
		// this.particle.start();
		this.addChild(this.particle);
		console.log(this.particle);

		this.bmp_tip1 = new egret.Bitmap();
		this.bmp_tip1.texture = RES.getRes('p1_tip1_png');
		this.bmp_tip1.anchorOffsetX = this.bmp_tip1.width / 2;
		this.bmp_tip1.anchorOffsetY = this.bmp_tip1.height / 2;
		this.bmp_tip1.x = 370;
		this.bmp_tip1.y = 1080;
		this.bmp_tip1.alpha = 0.5;
		this.addChild(this.bmp_tip1);
		egret.Tween.get(this.bmp_tip1, { loop: true }).to({ y: 1110, alpha: 1 }, 600, egret.Ease.cubicInOut).to({ y: 1080, alpha: 0.5 }, 600, egret.Ease.cubicInOut);

		this.bmp_tip2 = new egret.Bitmap();
		this.bmp_tip2.texture = RES.getRes('p1_t4_png');
		this.bmp_tip2.anchorOffsetX = this.bmp_tip2.width / 2;
		this.bmp_tip2.anchorOffsetY = this.bmp_tip2.height / 2;
		this.bmp_tip2.x = 356;
		this.bmp_tip2.y = 1030;
		this.bmp_tip2.scaleX=this.bmp_tip2.scaleY=0.8;
		this.addChild(this.bmp_tip2);
		// egret.Tween.get(this.bmp_tip2,{loop:true}).to({y:1103,alpha:0.5},600,egret.Ease.cubicInOut).to({y:1120,alpha:1},600,egret.Ease.cubicInOut);

		this.mc = new egret.MovieClip(MovieClipData.mcFactory1.generateMovieClipData("mc1"));
		this.mc.frameRate = 12;
		this.addChild(this.mc);
		this.mc.x = 0;
		this.mc.y = 360;
		this.mc.visible = false;
		// this.mc3.gotoAndPlay(1,1)
		// this.mc3.addEventListener(egret.Event.COMPLETE,this.loopHandler,this);
		this.addEventListener(egret.Event.ADDED_TO_STAGE, this.addToStage, this);
	}
	private addToStage(e: egret.Event): void {
		// this.bmp_t0.scaleX=this.bmp_t1.scaleY=0;


	}

	private t1: number;
	private t2: number;
	public In(): void {
		this.removeTween();

		this.alpha = 1;
		if (this.t1) {
			clearTimeout(this.t1);
		}
		if (this.t2) {
			clearTimeout(this.t2)
		}
		if (this.particle.visible) {
			this.particle.visible = false;
		}

		this.bmp_t0.y = 0;
		this.bmp_t0.alpha = 0;
		egret.Tween.get(this.bmp_t0).wait(200).to({ y: 70-30, alpha: 1 }, 1000, egret.Ease.cubicInOut);

		this.bmp_t1.y = 150 - 30;
		this.bmp_t1.alpha = 0;
		egret.Tween.get(this.bmp_t1).wait(1000).to({ y: 150, alpha: 1 }, 1000, egret.Ease.cubicInOut);

		// this.bmp_t2.scaleX = this.bmp_t2.scaleY = 1;
		this.bmp_t2.alpha = 0;
		this.bmp_t2.y = 278 - 30;
		egret.Tween.get(this.bmp_t2).wait(1100).to({ y: 278, alpha: 1 }, 1000, egret.Ease.cubicInOut);

		this.bmp_t3.y = 372 - 30;
		this.bmp_t3.alpha = 0;
		egret.Tween.get(this.bmp_t3).wait(1200).to({ y: 372, alpha: 1 }, 1000, egret.Ease.cubicInOut);

		this.bmp_tip2.y = 1020 - 30;
		this.bmp_tip2.alpha = 0;
		egret.Tween.get(this.bmp_tip2).wait(1200).to({ y: 1020, alpha: 1 }, 1000, egret.Ease.cubicInOut);

		var myThis = this;
		this.t1 = setTimeout(function () {
			// myThis.particle.stop();
		}, 4000);

		this.mc.alpha = 1;
		this.mc.visible = false;

		this.t2 = setTimeout(function () {
			myThis.particle.start();
			myThis.particle.visible = true;
			myThis.mc.visible = true;
			myThis.mc.gotoAndPlay(1);
		}, (2200));
	}

	public Out(): void {
		this.removeTween();

		this.particle.stop();
		if (this.t1) {
			clearTimeout(this.t1);
		}
		if (this.t2) {
			clearTimeout(this.t2)
		}
		egret.Tween.get(this.bmp_t0).to({ alpha: 0 }, 400);
		egret.Tween.get(this.bmp_t1).to({ alpha: 0 }, 400);
		egret.Tween.get(this.bmp_t2).to({ alpha: 0 }, 400);
		egret.Tween.get(this.bmp_t3).to({ alpha: 0 }, 400);
		egret.Tween.get(this.bmp_tip2).to({ alpha: 0 }, 400);
		egret.Tween.get(this.mc).to({ alpha: 0 }, 400);
	}

	private removeTween(): void {
		egret.Tween.removeTweens(this.bmp_t0);
		egret.Tween.removeTweens(this.bmp_t1);
		egret.Tween.removeTweens(this.bmp_t2);
		egret.Tween.removeTweens(this.bmp_t3);
		egret.Tween.removeTweens(this.bmp_tip2);
		egret.Tween.removeTweens(this.mc);
	}
}